package com.zzyl.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.VisitDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理模块管理")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "分页查询护理模块信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(Integer pageNum,
                                                                 Integer pageSize,
                                                                 String name,
                                                                 Integer status) {
        PageResponse<NursingProjectVo> pageInfo = nursingProjectService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@ApiParam(value = "护理项目数据传输对象", required = true)@RequestBody NursingProjectDto dto) {
        nursingProjectService.add(dto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询护理项目")
    public ResponseResult<NursingProjectVo> findById(@ApiParam(value = "护理项目ID", required = true)@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.searchById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult modifyNursingProject(@ApiParam(value = "护理项目", required = true)@RequestBody NursingProjectDto dto) {
        nursingProjectService.modifyNursingProject(dto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult modifyNursingProjectStatus(@ApiParam(value = "护理项目ID", required = true)@PathVariable Long id,
                                                     @ApiParam(value = "护理项目状态(0:禁用，1:启用)", required = true)@PathVariable Integer status) {
        nursingProjectService.modifyNursingProjectStatus(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteById(@ApiParam(value = "护理项目ID", required = true)@PathVariable Long id) {
        nursingProjectService.deleteById(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> findAll() {
        List<NursingProjectVo> nursingProjects = nursingProjectService.findAll();
        return success(nursingProjects);
    }
}
